import '../helper/dioHelper2.dart';

class ScsqQ {
  int ID;
  String STCD;
  String STNM;
  String TM;
  double H;
  double Q;
  String P;

  ScsqQ(this.ID, this.STCD, this.STNM, this.TM, this.H, this.Q, this.P);
  ScsqQ.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        STCD = json["STCD"],
        STNM = json["STNM"],
        TM = json["TM"],
        H = json["H"]*1.0,
        Q = json["Q"]*1.0,
        P = json["P"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'STCD': STCD,
        'STNM': STNM,
        'TM': TM,
        'H': H,
        'Q': Q,
        'P': P,
      };
  static Future<bool> Add(ScsqQ x1) async {
    var response = await DioHelper.Post("/ScsqQ/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(ScsqQ x1) async {
    var response = await DioHelper.Post("/ScsqQ/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(ScsqQ x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/ScsqQ/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<ScsqQ?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/ScsqQ/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new ScsqQ.fromJson(response.data);
    return null;
  }

  static Future<List<ScsqQ>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/ScsqQ/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <ScsqQ>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqQ.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<ScsqQ>> GetAllList() async {
    var response = await DioHelper.Get("/ScsqQ/GetAllList", {});
    var list1 = <ScsqQ>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqQ.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<ScsqQ>> GetNewList() async {
    var response = await DioHelper.Get("/SdzxData/GetQData3", {});
    var list1 = <ScsqQ>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqQ.fromJson(x));
      }
    }
    return list1;
  }


  static Future<List<ScsqQ>> GetListByTM(String sID,t1,t2) async {
    var response = await DioHelper.Get("/SdzxData/GetQListByTM?sID="+sID+"&TM1="+t1+"&TM2="+t2, {});
    var list1 = <ScsqQ>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScsqQ.fromJson(x));
      }
    }
    return list1;
  }
}
